//这个文件中还可以进行代码优化可以将return state.merge中的代码封装在一个函数里
// const changeData = (state,action) => ({
//     return state.merge({
    //   topicList: fromJS(action.topicList),
    //   articelList: fromJS(action.articelList),
    //   writerList: fromJS(action.writerList)
    // })
// })  在下面调用就ok了

import * as constants from './constants.js';
import { fromJS } from 'immutable'
//将在immutable中一如的fromJS 抱在这个对象外面使得这个普通对象变化为一个immutable对象
const defaultState = fromJS({
	topicList: [],
articelList: [],
 writerList: [],
 articlePage: 1,
 showScroll: false
})
//将if用switch case做替换
export default (state = defaultState, action) => {
	 switch(action.type){
    case constants.CHANGE_DATA:
    return state.merge({
      topicList: fromJS(action.topicList),
      articelList: fromJS(action.articelList),
      writerList: fromJS(action.writerList)
    })
    case constants.GET_MORE_LIST:
    // return state.set('articelList',state.get('articelList').concat(action.list))
    return state.merge({
      articelList: state.get('articelList').concat(action.list),
      articlePage: action.nextPage
    })
    case constants.CHANGE_SCROLL:
    return state.set('showScroll',true)
    case constants.CHANGE_SCROLLS:
    return state.set('showScroll',false)
	 	default:
	 	 return state;
	 	}
 }
